<!-- 合同选择下拉 -->
<template>
	<view style="width: 100%" @click="onClick">
		<u--input
			:placeholder="placeholder"
			:placeholderClass="placeholderClass"
			:placeholderStyle="placeholderStyle"
			:inputAlign="inputAlign"
			:fontSize="fontSize"
			:color="color"
			:prefixIcon="prefixIcon"
			:prefixIconStyle="prefixIconStyle"
			:suffixIcon="suffixIcon"
			:suffixIconStyle="suffixIconStyle"
			:border="border"
			:shape="shape"
			:customStyle="customStyle"
			v-model="title"
			disabled
			:disabledColor="disabledColor"
		></u--input>
	</view>
</template>

<script>
	import { erpOmcContractManagerFinalId, erpOmcContractManagerFinalIds } from '@/api/index.js'
	export default {
		data() {
			return {
				title:'', // 选中的标题名称
				isClick: false
			}
		},
		model: {
			prop: 'value',
			event: 'change',
		},
		props: {
			// 项目的id值
			projectId: {
				type: [String,Number],
				default: ''
			},
			// 是否多选
			multi: {
				type: [Boolean],
				default: false
			},
			// 是否查询所有 // 不传则就需要传projectId来查需要的列表
			allList: {
				type: [Boolean],
				default: false
			},
			signUnit: {
				type: String,
				default: ''
			},
			
			// 不知道干啥的后台这样写的
			status: {
				type: [String,Number],
				default: '2,3'
			},
			// 1代表收款合同, 2代表付款合同
			htlx: {
				type: [String,Number],
				default: ''
			},
			isCategoryType: {
				type: String,
				default: ''
			},
			changeStatus: {
				type: String,
				default: ''
			},
			showName: {
				type: String,
				default: ''
			},
			jytd: {
				type: String,
				default: ''
			},
			// 合同类型 - 框架合同和收款合同 默认收款合同
			contractType: {
				type: String,
				default: 'contract'
			},
			// 跳转页面的标题
			navigationBarTitle: {
				type: String,
				default: ''
			},
			// 对象字段
			objectField: {
				type: [String],
				default: 'basicForm.yzdw'
			},
			// 是否禁用
			disabled: {
				type: Boolean,
				default: false
			},
			// 选中的值
			value: {
				type: [String, Number],
				default: '',
			},
			// 输入框为空时的占位符
			placeholder: {
				type: [String, Number],
				default: '请选择',
			},
			// 指定placeholder的样式类，注意页面或组件的style中写了scoped时，需要在类名前写/deep/
			placeholderClass: {
				type: [String],
				default: '',
			},
			// 指定placeholder的样式，字符串/对象形式，如"color: red;"
			placeholderStyle: {
				type: [String, Object],
				default: 'color: #C0C4CC'
			},
			// 输入框内容对齐方式 - left | center | right
			inputAlign: {
				type: [String,],
				default: 'left',
			},
			// 输入框字体的大小
			fontSize: {
				type: [String, Number],
				default: '15px',
			},
			// 输入框字体颜色
			color: {
				type: [String],
				default: '#303133',
			},
			// 输入框前置图标
			prefixIcon: {
				type: [String],
				default: '',
			},
			// 前置图标样式，对象或字符串
			prefixIconStyle: {
				type: [String, Object],
				default: '',
			},
			// 输入框前置图标
			suffixIcon: {
				type: [String],
				default: 'arrow-down-fill',
			},
			// 前置图标样式，对象或字符串
			suffixIconStyle: {
				type: [String, Object],
				default: 'color: #B2B2B2',
			},
			// 边框类型，surround-四周边框，bottom-底部边框，none-无边框
			border: {
				type: [String],
				default: 'surround',
			},
			// 输入框形状，circle-圆形，square-方形
			shape: {
				type: [String],
				default: 'square',
			},
			customStyle: {
				type: [Object],
				default: () => {},
			}
		},
		watch: {
			// 监听value是否有值
			value: {
				handler (val, oldVal) {
					if (val) {
						this.getPurchaseDetail()
						
					} else {
						this.title = ''
					}
					if (oldVal) {
						this.$emit('change',val);
					}
				},
				immediate: true
			},
		},
		computed: {
			// 当是disabled为true改变禁用的颜色
			disabledColor () {
				if (this.disabled) {
					return '#f5f7fa'
				} else {
					return '#FFFFFF'
				}
			}
		},
		methods: {
			// 获取详情
			getPurchaseDetail () {
				if (!this.value) {
					this.title = ''
					return false
				}
				var empIdArr = this.value.split(',')
				if (!this.multi) {
					erpOmcContractManagerFinalId({id: this.value}).then(res => {
						if (res.success) {
							this.title = this.showName? res.result.htmc : res.result.finalNo
							this.$emit('detail', res.result)
							if (this.isClick) {
								this.$emit('input', res.result)
								this.isClick = false
							}
						}
					})
				} else {
					erpOmcContractManagerFinalIds({ids: this.value}).then(res => {
						if (res.success) {
							this.$emit('detail', res.result)
							if (this.isClick) {
								this.$emit('input', res.result)
								this.isClick = false
							}
							var title = ''
							if (this.showName) {
								res.result.map(value => {
									title = value.htmc + ',' + title
								})
							} else {
								res.result.map(value => {
									title = value.finalNo + ',' + title
								})
							}
							
							title = title.substring(0, title.lastIndexOf(','))
							this.title = title
						}
					})
				}
				
			},
			
			onClick () {
				if (!this.allList && !this.projectId) {
					this.$emit('onErr')
					return false
				}
				if (this.disabled) {
					return false
				}
				this.isClick = true
				uni.navigateTo({
					url: `/pages/common/selectContractManager?id=${this.value}&objectField=${this.objectField}&projectId=${this.projectId}&allList=${this.allList}&htlx=${this.htlx}&status=${this.status}&signUnit=${this.signUnit}&jytd=${this.jytd}&changeStatus=${this.changeStatus}&isMulti=${this.multi}&navigationBarTitle=${this.navigationBarTitle}&contractType=${this.contractType}`
				})
			}
		},
		mounted() {
			//初始化数据
			// this.queryDictModelByCodes(this.dictName);
		},
	}
</script>

<style lang="scss" scoped>
	
</style>